<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Apps\Apis\Common\DefCtl;

use Srv\Libs\Frame\Lang;

final class DefDeviceLangCtl extends DefAbstract
{
    private const TABLE_NAME                = 'idx_device_lang';
    private const FIELD_ID                  = 'ddlt_id';
    private const FIELD_KEY                 = 'ddlt_key';
    private const FIELD_NAME                = 'ddlt_name';
    public const EXT_NAME                  = 'name';
    public const KEY_LANG_ZH                = 'zh';
    public const KEY_LANG_EN                = 'en';

    /**
     * @return static
     * tag
     */
    public static function tag():self
    {
        $fieldExtList   = [self::EXT_NAME => self::FIELD_NAME];
        return parent::tag()->config(self::TABLE_NAME, self::FIELD_ID, self::FIELD_KEY, $fieldExtList);
    }

    /**
     * @return int
     * getDdltId
     */
    public function getDdltId():int
    {
        $ddltId     = $this->getDdltIdRequest();
        if($ddltId > 0) return $ddltId;
        return $this->getDdltIdDefault();
    }

    /**
     * @return int
     * getDdltIdRequest
     */
    public function getDdltIdRequest():int
    {
        return $this->getIdByKey(self::getLangType());
    }

    /**
     * @return int
     * getDdltIdDefault
     */
    public function getDdltIdDefault():int
    {
        return $this->getIdByKey(Lang::getDefaultLangType());
    }
}